package top.huhuiyu.myforum.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ControllerFilter {

  private static final Logger LOG = LoggerFactory.getLogger(ControllerFilter.class);

  @Pointcut("execution(public * top.huhuiyu.myforum.controller..*.*(..))")
  public void token() {
  }

  @Around("token()")
  public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
    LOG.debug("控制器拦截处理：" + pjp.getTarget());
    StringBuilder strArgs = new StringBuilder();
    Object[] args = pjp.getArgs();
    if (args != null && args.length > 0) {
      for (Object arg : args) {
        strArgs.append(arg).append("\r\n");
      }
    }
    LOG.debug("请求的参数：" + strArgs);
    Object result = pjp.proceed();
    LOG.debug("请求的结果：" + result);
    return result;
  }
}